package Admin;

import Server.Database.Database;
import static Server.Server.*;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 *
 * @author Paulius Dambrauskas
 */
public class AdminWindow  extends JFrame{
    private Database dataBase = null;
    public AdminWindow(){
        intDatabase();
        initInterface();
        
    }
    private void initInterface(){
        this.setTitle("Administravimas");
	this.setSize(600, 400);
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        String titles[] = { "Darbuotojai", "Blokai", "Automatika", "Filtrai" };
        JPanel panels[] = {new AdminWindowUsers(dataBase), new AdminWindowBlocks(dataBase), new AdminWindowAutomatics(dataBase), new AdminWindowFilters(dataBase)};
        for (int i = 0, n = titles.length; i < n; i++) {
            tabbedPane.addTab(titles[i], panels[i]);
        }
        this.add(tabbedPane, BorderLayout.CENTER);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addWindowListener( new WindowAdapter(){
            @Override
            public void windowClosing(WindowEvent e){
                try {
                    dataBase.closeResults();                    
                } catch (SQLException ex) {
                    System.out.println("sadffsaf");
                }
            }
        });
    }
    private void intDatabase(){
        try {
            dataBase = new Database(DATABASE_URL+":"+PORT+"/"+DATABASE_USERNAME, DATABASE_USERNAME, DATABASE_PASSWORD);
            
        } catch(Exception e){
            System.out.println("Administravimo pultas nepasiekia DB");
        }
    }
    public static void main(String[] args){
        new AdminWindow ();
    }
    
}
